package com.jmb.apiplatform.controller;

import com.jmb.apiplatform.common.PageResult;
import com.jmb.apiplatform.common.Result;
import com.jmb.apiplatform.exception.ValidException;
import com.jmb.apiplatform.pojo.ApiTestCaseRelyData;
import com.jmb.apiplatform.pojo.ApiTestCaseRelyDataTO;
import com.jmb.apiplatform.pojo.ApiTestCaseRelyDataVO;
import com.jmb.apiplatform.service.ApiTestCaseRelyDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "接口依赖")
@RestController
@RequestMapping("api/test/rely")
public class ApiTestCaseRoleDataController {
    @Autowired
    private ApiTestCaseRelyDataService apiTestCaseRelyDataService;

    @Operation(summary = "新增接口依赖")
    @PostMapping("save")
    public Result saveApiTestCaseRelyData(@RequestBody ApiTestCaseRelyData apiTestCaseRelyData, HttpServletRequest request) throws ValidException {
        apiTestCaseRelyDataService.saveApiTestCaseRelyData(apiTestCaseRelyData,request);
        return Result.success("新增成功");
    }
    @Operation(summary = "接口依赖列表")
    @GetMapping("list")
    public Result findApiTestCaseRelyDataList(ApiTestCaseRelyDataTO apiTestCaseRelyDataListTO) throws ValidException {
        PageResult<ApiTestCaseRelyDataVO> relyDataList = apiTestCaseRelyDataService.findApiTestCaseRelyDataList(apiTestCaseRelyDataListTO);
        return Result.success(relyDataList);
    }
    @Operation(summary = "查找接口依赖")
    @GetMapping("{relyId}")
    public Result findApiTestCaseRelyData(@PathVariable Integer relyId) throws ValidException {
        ApiTestCaseRelyDataVO relyData = apiTestCaseRelyDataService.findIfRelyData(relyId);
        return Result.success(relyData);
    }
    @Operation(summary = "修改接口依赖")
    @PostMapping("modify")
    public Result modifyApiTestCaseRelyData(@RequestBody ApiTestCaseRelyData apiTestCaseRelyData, HttpServletRequest request) throws ValidException {
        apiTestCaseRelyDataService.modifyIfRelyData(apiTestCaseRelyData,request);
        return Result.success("修改成功");
    }
    @Operation(summary = "删除接口依赖")
    @GetMapping("remove/{relyId}")
    public Result removeApiTestCaseRelyData(@PathVariable Integer relyId, HttpServletRequest request) throws ValidException {
        apiTestCaseRelyDataService.removeIfRelyData(relyId,request);
        return Result.success("删除成功");
    }

}
